// 编写 HTTP 服务
// http://nodejs.cn/api/
// https://www.runoob.com/nodejs/nodejs-http-server.html
var http = require("http");
const { send } = require("process");


function sendMessage(response, message) {
    console.log("sendMessage");
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end(message);
}

http.createServer(function(request, response) {
    // 发送 HTTP信息 先打印收到信息
    let requestPath = request.path;
    let requestMethod = request.method;
    let requestHost = request.host;

    console.log("requestPath:" + requestPath + " requestMethod:" + requestMethod + " requestHost:" + requestHost);
    
    // response.writeHead(200, {"Content-Type": "text/plain"});
    // response.end("Hello World, Node first Server! ");
    sendMessage(response, "Hello World, Node first Server! ");

}).listen(9009);

console.log("start node first server success!!!");


